<%@ page import="org.json.simple.*" %> <%--json_simple_1-1.jar--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    import = "java.sql.*" %>
<%
	request.setCharacterEncoding("UTF-8");
	
	String id = request.getParameter("u_id");
	String pw = request.getParameter("u_pass_1");
	String name = request.getParameter("u_name");
	String mail = request.getParameter("u_email");
	
	String url = "jdbc:oracle:thin:@155.230.193.42:1521:oraknu";
	String user = "system";
	String pass = "DBLab012345";
	Connection con = null;
	String sql = null;
	int result;
	
	JSONObject resultJson = new JSONObject();

	try
	{
		Class.forName("oracle.jdbc.driver.OracleDriver");
		System.out.println("success");
	}
	catch(ClassNotFoundException e)
	{
		System.err.println("error = " + e.getMessage());
		System.exit(1);
	}
	try
	{
		con = DriverManager.getConnection(url, user, pass);
	}
	catch(SQLException e)
	{
		System.err.println("sql error = " + e.getMessage());
		System.exit(1);
	}
	try
	{
		con.setAutoCommit(false);
		
		sql = "insert into USERTABLE(id, pw, name, mail) values(?,?,?,?)";
		
		PreparedStatement stmt = con.prepareStatement(sql);
		stmt.setString(1, id);
		stmt.setString(2, pw);
		stmt.setString(3, name);
		stmt.setString(4, mail);
		
		stmt.executeUpdate();
		
		con.commit();
		
		stmt.close();
		con.close();
		
		resultJson.put("result", true);
		//response.sendRedirect(회원가입성공화면);
	}
	catch(Exception e)
	{
		System.err.println("sql error = " + e.getMessage());
		resultJson.put("result", false);
		resultJson.put("log", "ID 또는 E-mail이 중복되었습니다.");
		//response.sendRedirect(회원가입실패화면);
	}
	out.print(resultJson);			
%>